package com.trembear.ucaroauth.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

/**
 * @author Junwei.Xiong
 * @description:
 * @create 2018-07-12 16:02
 */
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
    private Logger logger = LoggerFactory.getLogger(ResourceServerConfiguration.class);
    @Autowired
    private CustomAuthenticationEntryPoint customAuthenticationEntryPoint ;

    @Override
    public void configure(HttpSecurity http) throws Exception {
        logger.info("=========================111111111=========================");
        http
            .exceptionHandling()
                .authenticationEntryPoint(customAuthenticationEntryPoint)
                .and()
            .logout()
                .logoutUrl("/oauth/logout")
                .logoutSuccessHandler(customLogoutSuccessHandler())
                .and()
            .authorizeRequests()
                .antMatchers("/","/public","/failure").permitAll()
                .anyRequest().authenticated();
    }

    private LogoutSuccessHandler customLogoutSuccessHandler() {
        return new CustomLogoutSuccessHandler();
    }
}
